﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BestBuy.DTO;
using BestBuy.DAL;
namespace BestBuy.PageUser
{
    public partial class ReplysMessage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["IDDN"].ToString().Equals(""))
            {
                Response.Redirect("~/Account/Login.aspx");
            }
            if (!IsPostBack)
            {
                loadUnread();
            }  
        }
        private void loadUnread()
        {
            unread.Text = CMessage.countMessage(int.Parse(Session["IDDN"].ToString())).ToString();            
        }
        private List<DTOReplys> lireply = new List<DTOReplys>();
        protected List<DTOReplys> loadName()
        {
            foreach (var item in DTOListReply.List)
            {
                lireply.Add(item);
            }
            return lireply;
        }
        protected String getNameCompany(int iduser)
        {
            return Creplys.getName(iduser);
        }

        protected void btReply_Click(object sender, EventArgs e)
        {
            foreach (var item in DTOListReply.List)
            {
                BMessage rep = new BMessage();
                BMessage mess = CMessage.getMessage(item.Idmess);
                rep.IDTKReceiver = mess.IDTKSender;
                rep.IDTKSender = mess.IDTKReceiver;
                rep.Subject = tbReply.Text;
                rep.Date = DateTime.Now.ToShortDateString();
                rep.Source = mess.Source;
                rep.Status = 1;
                rep.IDContact = mess.IDContact;
                CMessage.addMessage(rep);
            }
            Response.Redirect("Message.aspx");
        }
    }
}